package com.yiren.dbaa.module.help_center.model;

import android.app.Activity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yiren.dbaa.constant.AddressConstant;
import com.yiren.dbaa.currency.api.CommonCallBack;
import com.yiren.dbaa.module.help_center.bean.ToolkitBean;
import com.yiren.dbaa.module.help_center.contract.ToolkitContract;
import com.yiren.dbaa.net.OkHttpUtils;
import com.yiren.dbaa.net.bean.TestBaseBean;
import com.yiren.dbaa.net.interf.StringCallback;

import java.util.List;

/**
 * @author lwb
 * @date :2022/7/28 17:14
 * @description:  工具包
 */
public class ToolkitModel implements ToolkitContract.Model {
   private Activity activity;
   private Gson gson;

    public ToolkitModel(Activity activity) {
        this.activity = activity;
        gson = new Gson();
    }

    @Override
    public void getToolKit(CommonCallBack callBack) {
        OkHttpUtils.getInstance().getStringByAsync(activity, AddressConstant.downloadToolKit(), new StringCallback() {
            @Override
            public void getString(String result) {
                TestBaseBean<List<ToolkitBean>> testBaseBean = gson.fromJson(result, new TypeToken<TestBaseBean<List<ToolkitBean>>>() {
                }.getType());
                callBack.success(testBaseBean.getData());

                super.getString(result);
            }

            @Override
            public void getFail() {
                super.getFail();
            }
        });
    }
}
